package answer

func longestPalindrome(s string) string {
	sBytes := []byte(s)
	left, right := 0, 0
	start, maxLen := 0, 0
	for left < len(s) {
		for right < len(s) {
			isPalindrome := isPalindrome(left, right, sBytes)
			if isPalindrome {
				if right-left > maxLen {
					start = left
					maxLen = right - left
				}
			}
			right++
		}
		left++
		right = left
	}
	return s[start : start+maxLen+1]
}

/**
 * @Description: 判断是否为回文串
 */
func isPalindrome(left, right int, target []byte) bool {
	for left < right {
		if target[left] != target[right] {
			return false
		}
		left++
		right--
	}
	return true
}
